#include "stdafx.h"
#include <time.h>

Log4c::Log4c(void)
{}

Log4c::~Log4c(void)
{}

void Log4c::log(const std::string& msg, LOG_LEVEL level)
{
	std::fstream file("log.txt",std::ios::app);
	// obtain time
	time_t lt;
	time(&lt);
	char ct[100]={0};
	ctime_s(ct,100,&lt);
	ct[strlen(ct)-1] = NULL;
	std::string strLevel;
	switch (level)
	{
	case LOG_LEVEL_LOG:
		strLevel = std::string("     LOG");
		break;
	case LOG_LEVEL_WARN:
		strLevel = std::string("    WARN");
		break;
	case LOG_LEVEL_ERROR:
		strLevel = std::string("   ERROR");
		break;
	default:
		break;
	}
	file<<"["<<ct<<" "<<strLevel<<"]"<<" "<<msg<<std::endl;

#if defined(_DEBUG) && defined(_WIN32)
	std::wstring ws;
	string2wstring(msg, ws);
	OutputDebugString(ws.c_str());
#endif

	if(level > LOG_LEVEL_WARN)
	{
		assert(false);
	}
}